package com.hl.vcd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hl.vcd.entity.LikeRecords;
import com.hl.vcd.mapper.LikeRecordsMapper;
import com.hl.vcd.service.LikeRecordsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 朱炫达
 */
@Service
@Transactional
public class LikeRecordsServiceImpl extends ServiceImpl<LikeRecordsMapper, LikeRecords> implements LikeRecordsService {
    @Override
    public void addLikeRecords(LikeRecords likeRecords) {
        baseMapper.insert(likeRecords);
    }

    @Override
    public void deleteLikeRecordsByUserIdAndVideoId(String userId, String videoId) {
        QueryWrapper<LikeRecords> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        wrapper.eq("video_id",videoId);
        baseMapper.delete(wrapper);
    }

    @Override
    public LikeRecords getLikeRecordsByUserIdAndVideoId(String userId, String videoId) {
        QueryWrapper<LikeRecords> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        wrapper.eq("video_id",videoId);
        return baseMapper.selectOne(wrapper);
    }
}
